//
//  TMAnnotationCell.m
//  国学培训用户端
//
//  Created by zhao caipu on 2018/9/25.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMAnnotationCell.h"
#import "TMAnnoSelectView.h"
@implementation TMAnnotationCell

- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self)
        
    {
        self.bounds = CGRectMake(0.f, 0.f, 30, 40);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickanimoter:)];
        tap.view.tag = self.zIndex;
        [self addGestureRecognizer:tap];
        self.image = [UIImage imageNamed:@"地标"];
        if (self.calloutView == nil)
        {
            /* Construct custom callout. */
            self.calloutView = [[NSBundle mainBundle] loadNibNamed:@"TMAnnoSelectView" owner:nil options:nil][0];
            self.calloutView.frame = CGRectMake(0, 0, annotation.title.length*12 + 30, 30);
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        }
        
        [self addSubview:self.calloutView];
    }
    return self;
}
- (void)clickanimoter:(UITapGestureRecognizer *)tap{
    if (self.block) {
        self.block(tap.view.tag);
    }
}
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
//    [super setSelected:selected animated:animated];
//    if (self.selected == selected)
//    {
//        return;
//    }
//    if (selected)
//    {
//        if (self.calloutView == nil)
//        {
//            /* Construct custom callout. */
//            self.calloutView = [[NSBundle mainBundle] loadNibNamed:@"TMAnnoSelectView" owner:nil options:nil][0];
//            self.calloutView.frame = CGRectMake(0, 0, 100, 44);
//            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
//                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
//        }
//
//        [self addSubview:self.calloutView];
//    }
//    else
//    {
//        [self.calloutView removeFromSuperview];
//    }
//
//
//}

@end
